package cn.ipenta.rpc;

import java.io.IOException;
import java.net.URISyntaxException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;


import cn.ipenta.PropertiesConfigurator;
import cn.ipenta.rpc.repo.BlockChainException;
import cn.ipenta.rpc.repo.BlockChainProvider;
import hprose.client.HproseClient;
import hprose.client.HproseHttpClient;

@Component
public class BlockChainBeanRegister {

	@Autowired
	private PropertiesConfigurator propertiesConfigurator;

	@Bean
	public BlockChainProvider getBlockChainProvider() {
		HproseClient hproseClient = null;
		try {
			hproseClient = HproseHttpClient.create(propertiesConfigurator.getUrl());
		} catch (IOException | URISyntaxException e) {
			throw new BlockChainException(e);
		}
		return hproseClient.useService(BlockChainProvider.class);
	}
}
